package presentation;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;

import javax.swing.JLabel;
import javax.swing.JPanel;

import control.CControl;

public class PStatusBar extends JPanel {
	private static final long serialVersionUID = 1L;
	private final int PANEL_HEIGHT = 30;

	public PStatusBar(CControl cControl) {
		this.setPreferredSize(new Dimension(0,PANEL_HEIGHT));
		this.setLayout(new BorderLayout());
		
		Font plainFont = new Font("Arial",Font.PLAIN,14);
		
		JPanel leftSide = new JPanel();
		leftSide.setLayout(new FlowLayout(FlowLayout.TRAILING,5,0));
		PPrefixText speed = new PPrefixText("Speed: ","--",
				" " + cControl.getRegisterUnit("FSN_Speed"),JLabel.LEFT, 
				plainFont,130,PANEL_HEIGHT);
		cControl.addRegisterObserver("FSN_Speed", speed);
		//PPrefixText rpm = new PPrefixText("RPM: ","--",
		//		"",JLabel.LEFT, plainFont,110,PANEL_HEIGHT);
		//cControl.addRegisterObserver("RPM", rpm);

		//PGearLabel gear = new PGearLabel("Gear: ","--",
		//		" " + cControl.getRegisterUnit("Gear"),JLabel.LEFT, 
		//		plainFont,100,PANEL_HEIGHT);
		//cControl.addRegisterObserver("Gear", gear);

		PSampleTimingLabel sampleTime = new PSampleTimingLabel(
				"Time between samples: ","--",
				" ms",JLabel.LEFT, plainFont,230,PANEL_HEIGHT);
		cControl.addRegisterObserver("DLN_DatalogCounter", sampleTime);
		
		leftSide.add(speed);
		//leftSide.add(rpm);
		//leftSide.add(gear);
		leftSide.add(sampleTime);
		JPanel rightSide = new JPanel();
		PStatusLabel dataStatus = new PStatusLabel(
				"Data connection: ","--"," ",JLabel.RIGHT,
				plainFont,180,PANEL_HEIGHT);
		cControl.addStreamStatusObserver(dataStatus);
		PStatusLabel webcamStatus = new PStatusLabel(
				"Webcam connection: ","--"," ",JLabel.RIGHT,
				plainFont,180,PANEL_HEIGHT);
		cControl.addVideoStatusObserver(webcamStatus);
		
		rightSide.setLayout(new FlowLayout(FlowLayout.TRAILING,0,0));
		rightSide.add(webcamStatus);
		rightSide.add(dataStatus);
		
		this.add(leftSide,BorderLayout.LINE_START);
		this.add(rightSide,BorderLayout.LINE_END);
	}
}
